package com.bookmanager.www.controller;

import com.bookmanager.www.common.utils.Result;
import com.bookmanager.www.entity.FlUser;
import com.bookmanager.www.mapper.FlUserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/10/02/2:13
 * @Description:
 */
@RestController
@Api(tags="查询用户管理")
@RequestMapping("/fl-searchUser")
@Slf4j
public class SearchUserController {
    @Resource
    FlUserMapper flUserMapper;
    /**
     * 邮箱查询用户是否存在
     */
    @GetMapping("/existUserByEmail")
    @ApiOperation(value = "通过邮箱判断用户是否存在")
    Result existUserByEmail(@RequestParam("email")String email)
    {
        log.info("打印一下传入的邮箱："+email);
        FlUser flUser = flUserMapper.selectUserByEmail(email);
        if(flUser!=null)
        {
            return Result.fail("该用户已注册","该邮箱已存在");
        }

        return Result.succ("该用户不存在可以注册！","");
    }

    /**
     * 手机号查询用户是否存在
     */
    @GetMapping("/existUserByPhoneNum")
    @ApiOperation(value = "通过手机号判断用户是否存在")
    Result existUserByPhoneNum(@RequestParam("phoneNum")String phoneNum)
    {
        FlUser flUser = flUserMapper.selectUserByPhoneNum(phoneNum);
        if(flUser!=null)
        {
            return Result.fail("该用户已经存在","");
        }

        return Result.succ("该用户不存在可以注册！","");
    }

    /**
     * 用户名查询用户是否存在
     * @param username
     * @return
     */
    @GetMapping("/existUserByUsername")
    @ApiOperation(value = "通过用户名判断用户是否存在",notes = "传入用户名 username")
    Result existUserByUsername(@RequestParam("username") String username){
        log.info("打印一下传入的用户名："+username);

        if(username!=null)
        {
            FlUser existUser = flUserMapper.selectUserByUsername(username);
            if(existUser!=null)
            {
                return Result.fail("该用户已经存在","");
            }
        }
        return Result.succ("该用户不存在可以注册！","");
    }
}
